package net.cathackers.devel.scmp.impl;

import java.util.HashMap;
import java.util.Map;

import net.cathackers.devel.exceptions.CATException;
import net.cathackers.devel.scmp.interfaces.Cache;
import net.cathackers.devel.scmp.interfaces.Cacheable;

public class HashCache<T, E extends Cacheable> implements Cache<T, E> {
    private Map<T, E> internalCache;
    public HashCache() {
	internalCache = new HashMap<T, E>();
    }
    @Override
    public void add(T key, E value) {
	internalCache.put(key, value);
    }
    @Override
    public boolean checkIfExists(T key) {
	return internalCache.containsKey(key);
    }
    @Override
    public E find(T key) {
	return internalCache.get(key);
    }
    @Override
    public E remove(T key) {
	return internalCache.remove(key);
    }
    @Override
    public void syncObjects() throws CATException{
	for (E profile : internalCache.values()) {
	    profile.syncObject();
	}
    }
}
